import { createRouter, createWebHashHistory } from "vue-router";
/* Layout */
import Layout from "@/layout/indexPc";
import Empty from "@/layout/empty";
import venRoutes from "./ven";

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/viewsPc/login"),
    name: "login",
    meta: { title: "登陆注册", affix: true },
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("@/views/error/404"),
    hidden: true,
  },
  {
    path: "/401",
    component: () => import("@/views/error/401"),
    hidden: true,
  },
  {
    path: "",
    component: Layout,
    redirect: "/index",
    children: [
      {
        path: "index",
        component: () => import("@/viewsPc/index"),
        name: "Index",
        meta: { title: "首页", icon: "dashboard", affix: true },
      },
      {
        path: "cityList",
        component: () => import("@/viewsPc/common/cityList"),
        name: "cityList",
        meta: { title: "J系统", affix: true },
      },
      {
        path: "venue",
        component: Empty,
        children: [
          {
            path: "list",
            component: () => import("@/viewsPc/venue/index"),
            name: "venueList",
            meta: { title: "场馆", affix: true },
          },
        ],
      },

      {
        path: "match",
        component: Empty,
        children: [
          {
            path: "list",
            component: () => import("@/viewsPc/match/index"),
            name: "matchList",
            meta: { title: "赛事", affix: true },
          },
          {
            path: "list/:id",
            component: () => import("@/viewsPc/match/detail"),
            name: "matchDetail",
            meta: { title: "赛事详情", affix: true },
          },
          {
            path: "list/:id/singleSign",
            component: () => import("@/viewsPc/match/singleSign"),
            name: "singleSign",
            meta: { title: "个人报名", affix: true },
          },
          {
            path: "list/:id/teamSign",
            component: () => import("@/viewsPc/match/teamSign"),
            name: "teamSign",
            meta: { title: "团队报名", affix: true },
          },
          {
            path: "list/:id/chooseCoach",
            component: () => import("@/viewsPc/match/chooseCoach"),
            name: "chooseCoach",
            meta: { title: "选择教练/领队/其他", affix: true },
          },
          {
            path: "list/:id/chooseSportsman",
            component: () => import("@/viewsPc/match/chooseSportsman"),
            name: "chooseSportsman",
            meta: { title: "选择运动员", affix: true },
          },
          {
            path: "list/:id/chooseProject",
            component: () => import("@/viewsPc/match/chooseProject"),
            name: "chooseProject",
            meta: { title: "选择参赛项目", affix: true },
          },
          {
            path: "list/:id/expenseDetails",
            component: () => import("@/viewsPc/match/expenseDetails"),
            name: "expenseDetails",
            meta: { title: "费用明细", affix: true },
          },
        ],
      },
      {
        path: "train",
        component: Empty,
        children: [
          {
            path: "list",
            component: () => import("@/viewsPc/train/index"),
            name: "trainPcList",
            meta: { title: "培训", affix: true },
          },
          {
            path: "list/:id",
            component: () => import("@/viewsPc/train/detail"),
            name: "trainPcDetail",
            meta: { title: "培训详情", affix: true },
          },
          {
            path: "list/:id/step1",
            component: () => import("@/viewsPc/train/signStep1"),
            name: "trainSignStep1",
            meta: { title: "培训报名", affix: true },
          },
          {
            path: "list/:id/step2",
            component: () => import("@/viewsPc/train/signStep2"),
            name: "trainSignStep2",
            meta: { title: "培训报名-餐食", affix: true },
          },
          {
            path: "list/:id/trainBill",
            component: () => import("@/viewsPc/train/trainBill"),
            name: "trainBill",
            meta: { title: "培训报名-费用明细", affix: true },
          },
        ],
      },
      {
        path: "center",
        component: () => import("@/viewsPc/center/index"),
        children: [
          {
            path: "myInfo",
            component: () => import("@/viewsPc/center/myInfo"),
            name: "myInfo",
            meta: { title: "个人中心" },
          },
          {
            path: "myTeam",
            component: () => import("@/viewsPc/center/teamInfo"),
            name: "myTeam",
            meta: { title: "我的团队" },
          },
          {
            path: "myMatch",
            component: () => import("@/viewsPc/center/myMatch"),
            name: "myMatch",
            meta: { title: "我的赛事" },
          },
          {
            path: "myTrain",
            component: () => import("@/viewsPc/center/myTrain"),
            name: "myTrain",
            meta: { title: "我的课程" },
          },
        ],
      },
    ],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

venRoutes.forEach((route) => {
  router.addRoute(route);
});

export default router;
